#include "Object.h"

Object::Object():
	pos(0,0,0),
	bound(0),
	vertices(0),
	indices(0)
{
}

Object::~Object(){
	//TODO: finish this
}

Object& Object::CreateBox(const Vec3& center, const Vec3& size){
	Object* ret = new Object();
	ret->vertices = new float[3*8];
	for (int x=0;x<2;x++){
		for (int y=0;y<2;y++){
			for (int z=0;z<2;z++){
				*Vec3::fromPointer(ret->vertices[(x*4+y*2+z)*3]) = center +
						Vec3(size.x*(x-0.5), size.y*(y-0.5), size.z*(z-0.5));
				/*
				ret->vertices[(x*4+y*2+z)*3+0] = center.x + size.x*(x-0.5);
				ret->vertices[(x*4+y*2+z)*3+1] = center.y + size.y*(y-0.5);
				ret->vertices[(x*4+y*2+z)*3+2] = center.z + size.z*(z-0.5);
				//*/
			}
		}
	}

	ret->indices = new unsigned int[6*2*3];
	//TODO: populate indices
	return *ret;
}

Object& Object::CreateTriangle(const Vec3& p0, const Vec3& p1, const Vec3& p2){
	Object* ret = new Object();
	ret->vertices = new float[3*3];
	*Vec3::fromPointer(ret->vertices[0*3]) = p0;
	*Vec3::fromPointer(ret->vertices[1*3]) = p1;
	*Vec3::fromPointer(ret->vertices[2*3]) = p2;

	ret->indices = new unsigned int[3];
	ret->indices[0] = 0;
	ret->indices[1] = 1;
	ret->indices[2] = 2;

	return *ret;
}
